//
//  ChartSocketController+Observe.m
//  EFSMobile
//
//  Created by Chuan on 11/18/15.
//  Copyright © 2015 Elephants Financial Service. All rights reserved.
//

#import "ChartSocketController+Observe.h"

//#import "EFSServiceManager.h"
//#import "EFSUserManager.h"
//#import "NSUserDefaults+EFS.h"



NSString *const kOptionalQuoteIdsKey = @"OptionalQuoteIds";
NSString *const kUserQuoteIdsConfig = @"UserQuoteIdsConfig";

static NSArray *GlobalPermisstionQuoteList = nil;
static NSArray *GlobalQuoteIds = nil;

@implementation ChartSocketController (Observe)

- (void)observeConnect
{
//    @weakify(self);
    
    
    //serverId变了 全局报价
//    [[RACObserve([EFSServiceManager sharedServiceManager], currentServerId) distinctUntilChanged]
//     subscribeNext:^(NSNumber *x) {
//         @strongify(self);
//         //重新获取品种列表
//         [self changeUserToVisitor:[x integerValue]];
//         [self connect];
//         [self getQuoteList];
//         
//         self.globalQuoteId = P(@"quote.globalQuoteId");
//     }];
//    
//    //有权限看到的品种列表
//    [RACObserve([EFSUserManager sharedManager], currentUser.token) subscribeNext:^(id x) {
//        @strongify(self)
//        NSArray * quoteList = [self.quoteList
//                               filterQuoteListWidthServerId:[[EFSServiceManager sharedServiceManager].currentServerId integerValue]
//                               withIsLogin:[EFSUserManager sharedManager].hasLogin
//                               withMarketQuoteSortArray:[self fetchMarketQuoteSort]];
//        self.permisstionQuoteList = quoteList;
//    }];
//    
//    //用户切换 自选列表
//    NSArray *ids = [[NSUserDefaults userDefaultWithGroup] objectForKey:kOptionalQuoteIdsKey];
//    if (!ids) {
//        ids = P3(@"quote.defaultCustomizedQuotes",GLOBALSETTING);
//        self.optionalQuoteIds = ids;
//    }

}

//- (BOOL)mUserConfig {
//    NSNumber *mdefaultConfig = [[NSUserDefaults userDefaultWithGroup] objectForKey:kUserQuoteIdsConfig];
//    return [mdefaultConfig boolValue];
//}

- (void)setMUserConfig:(BOOL)mUserConfig {
//    [[NSUserDefaults userDefaultWithGroup] setObject:@(mUserConfig) forKey:kUserQuoteIdsConfig];
//    [[NSUserDefaults userDefaultWithGroup] synchronize];
}

//- (NSArray *)optionalQuoteIds
//{
//    if (!self.mUserConfig) {
//        return P3(@"quote.defaultCustomizedQuotes",GLOBALSETTING);
//    }
//    
//    return [[NSUserDefaults userDefaultWithGroup] objectForKey:kOptionalQuoteIdsKey];
//}
//
//- (void)updateOptionQuoteIds:(NSArray *)optionalQuoteIds
//{
//    [[NSUserDefaults userDefaultWithGroup] setObject:optionalQuoteIds forKey:kOptionalQuoteIdsKey];
//    [[NSUserDefaults userDefaultWithGroup] synchronize];
//}
//
//- (void)setOptionalQuoteIds:(NSArray *)optionalQuoteIds
//{
//    self.optionalQuotes = optionalQuoteIds;
//    [[NSUserDefaults userDefaultWithGroup] setObject:optionalQuoteIds forKey:kOptionalQuoteIdsKey];
//    [[NSUserDefaults userDefaultWithGroup] synchronize];
//}
//
//- (void)setGlobalQuoteId:(NSArray *)globalQuoteId
//{
//    GlobalQuoteIds = globalQuoteId;
//}
//
//- (NSArray *)globalQuoteId
//{
//    return GlobalQuoteIds;
//}
//
//- (NSArray *)permisstionQuoteList
//{
//    return GlobalPermisstionQuoteList;
//}
//
//- (void)setPermisstionQuoteList:(NSArray *)permisstionQuoteList
//{
//    GlobalPermisstionQuoteList = permisstionQuoteList;
//}
//
//- (NSArray *)fetchMarketQuoteSort
//{
//    NSDictionary *codelist = P3(@"codelist",nil);
//    if (!codelist) {
//        return nil;
//    }
//    NSMutableArray *sortArray = [NSMutableArray array];
//
//    NSArray *array = [codelist[@"quotedatas"] copy];
//    for (NSDictionary *dict in array) {
//        for (NSDictionary *subDict in dict[@"List"]) {
//            NSMutableDictionary *quoteSortInfo = [NSMutableDictionary dictionary];
//            NSString *ID = subDict[@"ID"];
//            NSString *AbbrName = subDict[@"AbbrName"];
//            NSString *MarketTradingTarget = dict[@"MarketTradingTarget"];
//            NSNumber *Unit = subDict[@"Unit"];
//            if (!ID || !AbbrName || !MarketTradingTarget) {
//                continue;
//            }
//            [quoteSortInfo setValue:MarketTradingTarget forKey:@"MarketTradingTarget"];
//            [quoteSortInfo setValue:AbbrName forKey:@"AbbrName"];
//            [quoteSortInfo setValue:ID forKey:@"ID"];
//            if (Unit) {
//                [quoteSortInfo setValue:Unit forKey:@"Unit"];
//            }
//            [sortArray addObject:[quoteSortInfo copy]];
//        }
//    }
//
//    return sortArray;
//}
//
@end
